<?php

/**
 * @author Longuyvinh <longuyvinh.ny@gmail.com>
 *
 */
class ShoppingController extends BeController {

    public function __construct($id, $module = null) {
        parent::__construct($id, $module);
        $this->menu = array(
            array('label' => t('cms', 'Currency Setting'), 'url' => array('currency'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'Checkout Form'), 'url' => array('checkout'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'Delivery Method'), 'url' => array('delivery'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'Payment Method'), 'url' => array('payment'), 'linkOptions' => array('class' => 'button')),
        );
    }

    /**
     * The function that do Manage Shopping
     * 
     */
    public function actionCurrency() {
        $this->menu = array(
            array('label' => t('cms', 'Add Currency'), 'url' => array('shopping/currency/act/create'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'List Currency'), 'url' => array('shopping/currency/act/list'), 'linkOptions' => array('class' => 'button')),
        );
        $this->render('currency');
    }

    public function actionDeleteCurrency($id) {
        GxcHelpers::deleteModel('Currency', $id);
    }

    public function actionPayment() {
        $this->menu = array(
            array('label' => t('cms', 'Add New Payment'), 'url' => array('shopping/payment/act/create'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'List Payment Method'), 'url' => array('shopping/payment/act/list'), 'linkOptions' => array('class' => 'button')),
        );
        $this->render('payment');
    }

    public function actionUpdatepayment() {
        $this->menu = array(
            array('label' => t('cms', 'Add Payment Method'), 'url' => array('shopping/payment/act/create'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'List Payment Method'), 'url' => array('shopping/payment/act/list'), 'linkOptions' => array('class' => 'button')),
        );
        $this->render('payment_update');
    }

    public function actionDeletepayment($id) {
        GxcHelpers::deleteModel('PaymentMethod', $id);
    }

    public function actionCheckout() {
        $this->render('checkout');
    }

    public function actionChangeorder() {
        CheckoutForm::ajaxChangeOrderModule();
    }

    public function actionUpdateformstatus() {
        CheckoutForm::model()->updateByPk($_GET['form_id'], array('form_status' => $_GET['form_status']));
        echo $_GET['form_id'] . ':' . $_GET['form_status'];
    }

    public function actionDelivery() {
        $this->menu = array(
            array('label' => t('cms', 'Add Delivery Method'), 'url' => array('shopping/delivery/act/create'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'List Delivery Method'), 'url' => array('shopping/delivery/act/list'), 'linkOptions' => array('class' => 'button')),
        );
        $this->render('delivery');
    }

    public function actionDeleteDelivery($id) {
        GxcHelpers::deleteModel('DeliveryMethod', $id);
    }

    public function actionUpdateDelivery() {
        $this->menu = array(
            array('label' => t('cms', 'Add Delivery Method'), 'url' => array('shopping/delivery/act/create'), 'linkOptions' => array('class' => 'button')),
            array('label' => t('cms', 'List Delivery Method'), 'url' => array('shopping/delivery/act/list'), 'linkOptions' => array('class' => 'button')),
        );
        $this->render('delivery_update');
    }

    public function actionLoadcurrency($codeto) {
        $from = 'USD';
        $to = $codeto;
        $cc = new ECurrencyHelper();
        $rate1 = $cc->convert($from, $to, 1, ECurrencyHelper::USE_YAHOO);
        echo $rate1;
    }

}
